package tank02;

import java.awt.*;


import static tank02.MyGame.*;


/**
 * 子弹类
 */
public class Bullet implements Runnable{

    public static final int WIDTH = 6;
    public static final int HEIGHT = 6;

    //x坐标
    private int x;
    //y坐标
    private int y;
    //方向
    private int direction;
    //颜色
    private Color color;
    //速度
    private int speed = 5;
    //是否删除
    private boolean removed;

    public Bullet(int x, int y, int direction) {
        this.x = x;
        this.y = y;
        this.direction = direction;
    }

    public Bullet(int x, int y, int direction, Color color) {
        this(x,y,direction);
        this.color = color;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getDirection() {
        return direction;
    }

    public void setDirection(int direction) {
        this.direction = direction;
    }

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public boolean isRemoved() {
        return removed;
    }

    public void setRemoved(boolean removed) {
        this.removed = removed;
    }

    @Override
    public void run() {
        while(true){
            switch (direction){
                case DIRECTION_UP:
                    y -= speed;
                    break;
                case DIRECTION_DOWN:
                    y += speed;
                    break;
                case DIRECTION_LEFT:
                    x -= speed;
                    break;
                case DIRECTION_RIGHT:
                    x += speed;
                    break;
            }
            if(x < 0 || x > PANEL_WIDTH || y < 0 || y > PANEL_HEIGHT){
                removed = true;
                break;
            }
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
